<template>
  <div class="container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
          <navbar></navbar>
    </div>
    <!-- 面包屑导航 -->
    <div class="Box">
      <div class="table_tab">
        <div class="inquiry">
          <div class="headerbox">
            <div class="header">
              数据筛选
            </div>

          </div>
          <el-form
            :inline="true"
            ref="queryForm"
            :model="search"
            size="small"
             class="search-form"
          >
           <el-form-item  label="客户信息">
              <el-input v-model="form.customerInfo" placeholder="请输入客户信息"></el-input>
          </el-form-item>
           <el-form-item label="订单号">
              <el-input v-model="form.orderNo" placeholder="请输入订单号"></el-input>
          </el-form-item>
          <el-form-item label="订单日期">
              <el-date-picker
              v-model="allotDate"
              type="daterange"
              unlink-panels
              clearable
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              @change="onChangeTime"
              value-format="yyyy-MM-dd HH:mm:ss"
             :default-time="['00:00:00', '23:59:59']">
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="来源平台">
              <el-select
                  v-model="form.platformId"
                  placeholder="请选择来源平台"
                  filterable
                  clearable
              >
                <el-option
                    v-for="item in platformList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                >
                </el-option>
              </el-select>
          </el-form-item>
            <el-form-item>
              <el-button
                @click="searchEvent()"
                plain
                type="primary"
                >搜索</el-button
              >
              <el-button plain @click="fetchData('reset')" type="primary">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="inquiryTab">
          <div class="inquiryTab_header">
            <div class="tabTitle">积分流水</div>
          </div>
          <div class="table">
           <matrix-table :dataList="manage.page.list" :config="manage.config" :loading="manage.loading"></matrix-table>
             <div class="page" >
               <div class="block">
                  <el-pagination
                      @size-change="onSizeChange"
                      @current-change="onCurrentChange"
                      :current-page="manage.page.pageNo"
                      :page-size="manage.page.pageSize"
                      :page-sizes="[3, 5, 10, 20, 50]"
                      layout="total,sizes, prev, pager, next"
                      :total="manage.page.totalNum">
                  </el-pagination>
                </div>
             </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import MatrixTable from './components/MatrixTable.vue'
import common from './mixins/common'
import navbar from '@/components/navbar.vue'
export default {
  mixins: [common],
  watch: {
    $route :{
      handler: function(newV, oldV){
        this.fetchData()
      },
      deep: true
    },
  },
  components: {
    MatrixTable,
    navbar
  },
  data () {
    return {
      form: {
        monthDate: '', // string 佣金月份
        customerInfo: '', // string or null 客户信息
        orderNo: '', // string or null 订单号
        orderDateStart: '', // string or null 订单日期-开始
        orderDateEnd: '', // string or null 订单日期-结束
        platformId: '', // integer or null 来源平台 数据来源：/order/v1-2/platform/dataList
        updatedDateStart: '', // integer or null 更新时间-开始
        updatedDateEnd: '' // string or null 更新时间-结束
      },
      platformList: [], // 平台列表
      manage: {
        loading: false,
        page: { list: [], pageNo: 1, pageSize: 10, totalNum: 0, currentPage: 1 }, // 员工业绩统计(XX年XX月)
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: [
          { prop: 'customerName', label: '客户信息', slot: 'customerName' },
          { prop: 'orderNo', label: '订单号' },
          { prop: 'goodsName', label: '订单商品' },
          { prop: 'orderTime', label: '订单日期' },
          { prop: 'receivableAmount', label: '订单金额', slot: 'receivableAmount', width: 100 },
          { prop: 'points', label: '积分' },
          { prop: 'platformName', label: '来源平台' },
          { prop: 'orderStatusLabel', label: '订单状态' },
          { prop: 'updatedTime', label: '更新时间' }
        ]
      },
      parArray: [],
      search: {
        platformId: ''
      },
      allotDate: [] // 订单日期
    }
  },
  mounted () {

  },
  created () {
	this.form.monthDate = this.$route.query.monthDate
    this.fetchData()
    this.getPlatformList() // 获取平台列表
    // 权限设定判断
    this.limits = JSON.parse(sessionStorage.getItem('limit'))
    const params = this.limits.buttonTreeDto.filter(
      (item) => item.menuCode === 'categoryManage'// 菜单管理里面的菜单编码
    )
    params[0].buttonList.forEach((item) => {
      this.parArray.push(item.code)
    })
    console.log(this.parArray)
    // 权限设定判断
    document.onkeydown = (e) => {
      const key = window.event.keyCode
      if (key == 13) {
        this.searchEvent()
      }
    }
  },
  beforeRouteLeave (to, form, next) {
    document.onkeydown = null
    next()
  },

  methods: {
    onChangeTime (e) { // 订单日期
      if (e) {
        this.form.orderDateStart = e[0]
        this.form.orderDateEnd = e[1]
      } else {
        this.form.orderDateStart = ''
        this.form.orderDateEnd = ''
      }
    },
    searchEvent () {
      this.manage.page.pageNo = 1
      this.fetchData('search')
    },
    // 获取平台列表
    getPlatformList () {
      const params = {}
      this.$api.platformDataList(params).then((res) => {
        this.platformList = res.data
      }).catch((err) => {
        console.log(err)
      })
    },
    onSizeChange (sizeChange) {
      this.manage.page.pageNo = 1
      this.manage.page.currentPage = 1
      this.manage.page.pageSize = sizeChange
      this.fetchData('search')
    },
    onCurrentChange (currentChange) {
      this.manage.page.pageNo = currentChange
      this.fetchData('search')
    },
    fetchData (type) {
      this.manage.loading = true
      if (type === 'reset') {
        this.manage.page.pageNo = 1
        this.manage.page.pageSize = 10
        this.manage.page.currentPage = 1
        this.form = {}
        this.allotDate = []
      }
      let params = {
        pageNo: this.manage.page.pageNo,
        pageSize: this.manage.page.pageSize,
        monthDate: this.$route.query.monthDate
      }
      if (type === 'search') {
        // this.manage.page.currentPage = 1
        // this.manage.page.pageNo = 1
        // params.pageNo = 1
        params.orderDateStart = this.form.orderDateStart
        params.orderDateEnd = this.form.orderDateEnd
        params = Object.assign({}, params, this.form)
		console.log('params=',params,this.form)
        // 去除字符串 前后 空格
        for (const item in params) { if (typeof params[item] === 'string') { params[item] = params[item].trim() } }
      }
      this.$api.matrixDetailPageListIntegral(params).then((res) => {
        if (res.code === 0) {
          this.manage.loading = false
          console.log(res)
          this.manage.page.list = res.data.list
          this.manage.page.totalNum = res.data.totalNum
        } else {
          this.manage.loading = false
        }
      }).catch((err) => {
        console.log(err)
        this.manage.loading = false
      })
    }
  }
}
</script>
<style scoped lang="scss">
.Box {
  display: flex;
  justify-content: flex-start;
  width: 100%;

  .table_tab {
    width: 100%;
    margin-bottom: 50px;
  }
}
.table {
  border-radius: 5px;
  width: 100%;
}

.header {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: bold;
  color: #333333;
  padding-bottom: 10px;
}

.inquiry {
  background: #fff;
  padding: 10px 20px 10px 20px;
  border-radius: 5px;
  .el-form {
    margin-top: 10px;
  }
}
.inquiryTab {
  background: #fff;
  padding: 10px 20px 20px 20px;
  border-radius: 5px;
  .el-form {
    margin-top: 10px;
  }
  margin-top: 20px;
  .inquiryTab_header {
    display: flex;
    justify-content: space-between;
    /deep/ .el-button {
      height: 40px;
    }
  }
}

/deep/.el-table__expand-icon > .el-icon {
  color: transparent;
}

.table {
  margin-top: 10px;
  border: 1px solid #e8eaec;
  border-radius: 0;
  /deep/ .el-input--suffix .el-input__inner {
    color: #000;
    width: 104px;
    box-shadow: none;
  }
  /deep/ .el-button {
    padding: 10px 13px;
  }
}

.page {
  text-align: right;
  width: 100%;
  background: #f5f5f5;
  padding-right: 30px;
  position: fixed;
  bottom: 0px;
  right: 0px;
  z-index: 5;

  span {
    font-size: 14px;
    color: #666;
    display: inline-block;
    margin-left: 10px;
  }
  .el-pagination {
    display: inline-block;
    vertical-align: middle;
  }
}
/deep/.el-table__row:hover {
  color: rgb(45, 125, 223);
}
/deep/.el-dialog__header {
  padding: 20px 20px 20px 20px;
  font-family: PingFang SC;
  font-weight: bold;
  line-height: 25px;
  color: #333333;
}
/deep/.el-dialog {
  border-radius: 10px;
}
/deep/.el-dialog__headerbtn {
  top: 15px;
}
.headerbox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  border-bottom: 1px solid #ededed;
  padding-bottom: 10px;
}

.tabTitle {
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 25px;
  color: #333333;
  opacity: 1;
  margin-top: 10px;
  margin-bottom: 20px;
}
/deep/.el-form-item__label {
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #333333;
}

/deep/ .el-dialog__footer {
  margin-top: -20px;
  padding-top: 20px;
}
/deep/.el-table thead {
  font-size: 16px;
  font-family: PingFang SC;
  font-weight: bold;
  line-height: 22px;
  color: #333333;
  opacity: 1;
}

.btnClass{
  margin-top: 20px;
  display: flex;
  justify-content: right;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  .el-form-item {
    width: 100%;
    max-width: 303px;
    min-width: 299px;
    /deep/.el-form-item__label{
      width: 70px;
    }
    /deep/.el-form-item__content {
      width: calc(100% - 70px);
      .el-select, .el-date-editor, .el-cascader {
        width: 100%;
      }
    }
  }
}
</style>
